Source Code Repository Adapters

Purpose

Source code management tools are an important component in the DevOps landscape. They help you store and maintain your source code. In ecosystems involving distributed development, a centralized repository system facilitates better coordination among stakeholders and establishes a single source of truth.

Prominent examples of source code repository tools that support Git functionality include GitHub, GitLab, and Bitbucket, among many others.

The Calibo Accelerate platform already supports all the leading source code repository tools that you need for the storage and maintenance of your source code for cloud-native application development. The platform also enables you to create highly adaptable adapters, which facilitate smooth and efficient integration of new source code repository tools that may not be available in the platform out-of-the-box. The following section contains a well defined interface that you need to build an adapter to interact with a new source code repository tool.

Interface:

Interface to build an adapter to interact with a new source code repository tool

Copy

public interface ElabSourceCodeRepositoryService {

public interface ElabSourceCodeRepositoryService { 
 
   ElabUserBean createUser(final String email, String username, final String name)
 
    boolean checkIfUserExist(String username)
 
    boolean testConnection()
 
    String getUsernameByEmail(final String email)
 
   ElabProjectRepositoryBean createProject(final String tenant, final String title, final String templateUri, final ElabUserBean owner, final Set<ElabUserBean> owners, final Set<ElabUserBean> members)
 
   ElabUserBean addProjectMember(final String projectId, final String userId, String email, Set<String> roles, ElabProjectRepositoryEntity projectRepository)
 
   ElabUserBean addProjectOwner(final String projectId, final String userId, final String email)
 
   Map<String, ElabPushEventsResponseBean> getPushEvents(final String userId, final String projectId, final Date after, final Date before, final ProjectMetricsLevelEnum projectMetricsLevel)
 
   String deleteProjectMember(final String projectId, final String userId, final Set<String> userRoleIds)
 
   void createProjectBranch(ElabBranchRequestBean req)
 
   void createProjectMergeRequest(Long id, ElabProjectMergeRequestBean req)
 
   List<String> getProjectBranch(String repoId, String orgName, String repoName, String projectKey)
 
   List<ElabCommitResponseBean> getProjectCommits(String id, String ref, ElabProjectEntity elabProjectEntity)
 
    Boolean addOrUpdateFileToSourceCodeRepository(String id, String commitAction, ElabProjectRepositoryAddFileRequestBean bean)
 
    String deleteRepository(final ElabProjectRepositoryEntity projectRepository)
 
   ELabFileUpdateResponseBean updateFileContentToRepository(final String id, final String filePath, final ElabFileUpdateRequestBean bean)
 
   ElabFileContentResponseBean getFileContent(final String id, final String branch, 
         final String filePath, boolean isUrlEncoded, String projectKey, String repoName)
 
   Boolean isRepoAvailable(String name, String groupName, String userName, String projectKey, String groupPath)
 
   Boolean checkFileExist(final String id, final String branch,final String filePath)
 
 
} 

 

The following are the supporting beans for the implementation of this interface.

Package: lazsa.adapter.sourcecode.beans

  • Bean for holding user details

    Copy
    public class ElabUserBean { 
     
        private String email; 
        private String name; 
        private String userCode; 
     
        private String userName; 
        private ProviderEnum userProvider; 
        private ElabUserCredentialBean credential; 
    } 
  • Bean for holding data of repository project

    Copy
    public class ElabProjectRepositoryBean { 
     
       private String uri; 
       private String projectKey; 
       private String orgName; 
       private String visibility; 
       private String repositoryCode; 
       private ProviderEnum repositoryProvider; 
       private String sonarProjectKey; 
     
    } 
  • Bean for holding push events

    Copy
    public class ElabPushEventsResponseBean { 
     
       private String date; 
       private int count; 
     
       public ElabPushEventsResponseBean(final String date) { 
          this.date = date; 
       } 
     
    } 
  • Request bean for branch creation

    Copy
    public class ElabBranchRequestBean { 
       private String repoId; 
       private String newBranchName; 
       private String refBranchName; 
     
    } 
  • Request bean for peer review creation

    Copy
    public class ElabProjectMergeRequestBean { 
     
     
        @NotBlank 
        @ApiModelProperty(required = true, value = "Source Branch Name") 
        private String sourceBranch; 
     
        @NotBlank 
        @ApiModelProperty(required = true, value = "Target Branch Name") 
        private String targetBranch; 
     
        @NotBlank 
        @ApiModelProperty(required = true, value = "Title of the merge request") 
        private String title; 
     
        private int[] assigneeIds ; 
     
        private int assigneeId; 
     
        private String description; 
     
        private Boolean removeSourceBranch; 
     
    } 
  • Bean for holding commits data

    Copy
    public class ElabCommitResponseBean { 
       private String id; 
       private String short_id; 
       private String title; 
       private String created_at; 
       private String message; 
       private String author_name; 
       private String author_email; 
       private String authored_date; 
       private String committer_name; 
       private String committer_email; 
       private String committed_date; 
       private String webUrl; 
       private String branchUrl; 
     
    } 
  • Request bean for adding elements to repository

    Copy
    public class ElabProjectRepositoryAddFileRequestBean { 
     
       @NotBlank 
       @ApiModelProperty(required = true, value = "Name of the branch to commit into") 
       private String branch; 
     
       @NotBlank 
       @ApiModelProperty(required = true, value = "Commit Message") 
       private String message; 
     
       @NotBlank 
       @ApiModelProperty(required = true, value = "Full path to the file. Ex. lib/class.rb") 
       private String filePath; 
     
       @NotBlank 
       @ApiModelProperty(required = true, value = "File content") 
       @ToString.Exclude 
       private String content; 
     
    }
  • Request bean for file updation in repository

    Copy
    public class ElabFileUpdateRequestBean { 
        private String branch; 
        private String content; 
        private String commit_message; 
    } 
  • Response for file updation in repository

    Copy
    public class ELabFileUpdateResponseBean { 
        private String branch; 
        private String file_path; 
    } 
  • Bean for holding the file content details

    Copy
    public class ElabFileContentResponseBean { 
        private String file_name; 
        private String file_path; 
        private Long size; 
        private String encoding; 
        private String content; 
        private String content_sha256; 
        private String ref; 
        private String blob_id; 
        private String commit_id; 
        private String last_commit_id; 
    }

 

Database structure for storing repository mappings with platform entities

Copy
public class ElabProjectRepositoryEntity extends Auditable<String> { 
 
 
   @Id 
   @GeneratedValue(generator = "uuid") 
   @GenericGenerator(name = "uuid", strategy = "org.hibernate.id.UUIDGenerator") 
   @Column(name = "id") 
   private String id; 
 
   @Column(name = "title", nullable = false, columnDefinition = "VARCHAR(255)") 
   private String title; 
 
   @Column(name = "repo_name", nullable = true, columnDefinition = "VARCHAR(255)") 
   private String repoName; 
 
   @Enumerated(EnumType.STRING) 
   @Column(name = "repo_type", nullable = true, columnDefinition = "VARCHAR(30)") 
   private RepoType repoType; 
 
   @Column(name = "description", nullable = true, columnDefinition = "TEXT") 
   private String description; 
 
   @Column(name = "tech_stack_id", nullable = true) 
   private String techStackId; 
 
   @Column(name = "tech_stack_name", nullable = true, columnDefinition = "VARCHAR(60)") 
   private String techStackName; 
 
   @Column(name = "uri", nullable = true, columnDefinition = "TEXT") 
   private String uri; 
 
   @Column(name = "repository_code", nullable = true, columnDefinition = "VARCHAR(60)") 
   private String repositoryCode; 
 
   @Enumerated(EnumType.STRING) 
   @Column(name = "repository_provider", nullable = false, columnDefinition = "VARCHAR(60)") 
   private ProviderEnum repositoryProvider; 
 
   @Column(name = "sonar_project_key") 
   private String sonarProjectKey; 
 
   @ElementCollection(fetch = FetchType.EAGER) 
   @CollectionTable(name = "elab_project_repository_tag", joinColumns = @JoinColumn(name = "repository_id")) 
   @Column(name = "tag", nullable = false) 
   private Set<String> tags; 
 
   @Column(name = "setting_id") 
   private String settingId; 
 
   @Column(name = "workstream_id") 
   private String workstreamId; 
 
   @Column(name = "release_id") 
   private String releaseId; 
 
   @Column(name = "multi_instance_id") 
   private String multiInstanceId; 
 
   // This is the project key for the bitbucket, Group Path for gitlab 
   @Column(name = "project_key") 
   private String projectKey; 
 
   // this is Organisation for github and Workspace for bitbucket 
   @Column(name = "org_name") 
   private String orgName; 
 
   @Column(name = "visibility") 
   private String visibility; 
 
   //Group ID for gitlab 
   @Column(name = "group_path_id") 
   private String groupPathId; 
 
   @Enumerated(EnumType.STRING) 
   @Column(name = "status", nullable = false, columnDefinition = "VARCHAR(60)") 
   private StatusEnum status = StatusEnum.ACTIVE; 
 
 
} 

 

Detailed implementation of the exposed interfaces

The interface defines methods that help in interacting with the source code repository tools. The following are the usage details of each method:

Interface Method Usage
ElabUserBean createUser(final String email, String username, final String name) Facilitates the creation of a user in the source code repository tool, which is integrated within the platform.
boolean checkIfUserExist(String username) Checks whether the user exists in the source code repository tool.
boolean testConnection() Verifies the connection status with the integrated tool.
String getUsernameByEmail(final String email) Retrieves the username in the tool using the email of the platform user.

ElabProjectRepositoryBean createProject(final String tenant, final String title, final String templateUri, final ElabUserBean owner, final Set<ElabUserBean> owners, final Set<ElabUserBean> members)

Creates a repository in the source code tool, capturing details of the code repository and its associated users.

ElabUserBean addProjectMember(final String projectId, final String userId, String email, Set<String> roles, ElabProjectRepositoryEntity projectRepository) Adds users to the created project, specifying their roles.
ElabUserBean addProjectOwner(final String projectId, final String userId, final String email) Designates users as owners of the project.
String deleteProjectMember(final String projectId, final String userId, final Set<String> userRoleIds) Removes users from the assigned project.
void createProjectBranch(ElabBranchRequestBean req) Creates branches for the repository project.
void createProjectMergeRequest(Long id, ElabProjectMergeRequestBean req) Initiates a peer review request for proposed changes to be incorporated into the project.
List<String> getProjectBranch(String repoId, String orgName, String repoName, String projectKey) Retrieves the available branches within the project.

Map<String, ElabPushEventsResponseBean> getPushEvents(final String userId, final String projectId, final Date after, final Date before, final ProjectMetricsLevelEnum projectMetricsLevel)

Returns data on all events related to a particular user within a given project.
List<ElabCommitResponseBean> getProjectCommits(String id, String ref, ElabProjectEntity elabProjectEntity) Provides a list of all commits documenting code changes within the specified project.
Boolean addOrUpdateFileToSourceCodeRepository(String id, String commitAction, ElabProjectRepositoryAddFileRequestBean bean) Facilitates the addition or modification of files within the project's source code repository.
void deleteRepository(final ElabProjectRepositoryEntity projectRepository) Deletes the specified project repository.
ELabFileUpdateResponseBean updateFileContentToRepository(final String id, final String filePath, final ElabFileUpdateRequestBean bean) Updates the content of a file within the project's repository.

ElabFileContentResponseBean getFileContent(final String id, final String branch, final String filePath, boolean isUrlEncoded, String projectKey, String repoName)

Retrieves the content of a specified file within a particular branch of the project.
Boolean isRepoAvailable(String name, String groupName, String userName, String projectKey, String groupPath) Checks whether the repository is present in the system.
Boolean checkFileExist(final String id, final String branch,final String filePath) Verifies whether a file exists within the given branch of the specified project.

 

Related Topics Link IconRecommended Topics

What's next? Integrate with External Data Catalogs